package com.imooc.demo.pattern.proxy.jdk.dynamic;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class AplipayInvocationHandler implements InvocationHandler {
    /**
     * 被代理对象
     */
    private Object target;

    public AplipayInvocationHandler(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        beforePay();
        Object result = method.invoke(target, args);
        afterPay();
        return result;
    }

    private void afterPay() {
        System.out.println("支付给xxx ");
    }

    private void beforePay() {
        System.out.println("从招行取款");
    }
}
